package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.HomeTab;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/12/18
 */

public class HomeTabAdapter extends RecyclerAdapter<HomeTab, HomeTabAdapter.TabViewHolder> {

    public HomeTabAdapter(Context context, List<HomeTab> dataList) {
        super(context, dataList);
    }

    @Override
    public TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_home_tab, null);
        return new TabViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TabViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TabViewHolder extends RecyclerAdapter.BaseViewHolder{
        @BindView(R.id.tab_image)
        TextView tabImage;

        public TabViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final HomeTab tab = dataList.get(position);
            tabImage.setBackgroundResource(tab.getId());
            tabImage.setEnabled(!tab.isChecked());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(tab);
                }
            });
        }
    }
}
